Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add path regex check to locks #174

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

Add path regex check to locks #174

wants to merge 12 commits into from

Conversation

@oliviagolden0 oliviagolden0 marked this pull request as ready for review May 16, 2024 20:30
rules/engine.go Outdated
@@ -69,7 +70,7 @@ type V3Engine interface {
AddRule(rule DynamicRule,
lockPattern string,
callback V3RuleTaskCallback,
options ...RuleOption)
options ...RuleOption) error
Copy link
Contributor

@kramvan1 kramvan1 May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Humm, this would be a major hit to all services to handle this new error.

Maybe we should consider a e.logger.Fatal(...) or a panic("Rule ID option missing") instead? That way only those that have issues will affected.

And then will need to make this a major version bump and an announcement in the armada-dev channel.

rules/engine.go Outdated
@@ -69,7 +70,7 @@ type V3Engine interface {
AddRule(rule DynamicRule,
lockPattern string,
callback V3RuleTaskCallback,
options ...RuleOption)
options ...RuleOption) error
AddPolling(namespacePattern string,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might also have to check the AddPolling namespacePattern, but have not looked into that one yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AddPolling calls AddRule so I think it should be okay unless the check should be higher up in the chain

func (e *v3Engine) AddPolling(namespacePattern string, preconditions DynamicRule, ttl int, callback V3RuleTaskCallback) error {

rules/engine.go Outdated
@@ -169,8 +170,13 @@ func (e *v3Engine) SetWatcherWrapper(watcherWrapper WrapWatcher) {
func (e *v3Engine) AddRule(rule DynamicRule,
lockPattern string,
callback V3RuleTaskCallback,
options ...RuleOption) {
options ...RuleOption) error {
validPath := regexp.MustCompile(`^[[:alnum:] \:\/\"\'\_\.\,\*\=\-]*$`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be pushed out to a static var, no need to do this every time.
Maybe add a cmt with it to spell out the char to make it easier to know what is valid?

rules/engine.go Outdated
func (e *v3Engine) AddRule(rule DynamicRule,
lockPattern string,
callback V3RuleTaskCallback,
options ...RuleOption) {
e.addRuleWithIface(rule, lockPattern, callback, options...)
if !validPath.MatchString(lockPattern) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not including check that the path contains "lock" since /crawler/compliance-engine /armada-ingress/:region/clusters/:clusterid/ingress_update paths don't contain

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Humm, I think we should push to get that changed and then announce in armada-dev that this will be required from now on.

rules/engine.go Outdated
e.addRuleWithIface(rule, lockPattern, callback, options...)
if !validPath.MatchString(lockPattern) {
e.logger.Fatal("Path contains an invalid character")
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for else, when above is fatal?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants